
import 'package:flutter/material.dart';
import 'package:flutter_demo/route/RouteWrapper.dart';

void main(){
  runApp(MaterialApp(
    onGenerateRoute: onGenerateRoute,
    home: Scaffold(
      appBar: AppBar(
        title:Text("组件合集")
      ),
      body:MstartWidget(),
    ),
  ));
}
class MstartWidget extends StatelessWidget {
  DateTime? _lastPressedAt; //上次点击时间
  @override
  Widget build(BuildContext context) {
    return WillPopScope( onWillPop: () async {
      if (_lastPressedAt == null ||
          DateTime.now().difference(_lastPressedAt!) > Duration(seconds: 1)) {
        //出生日期
        final birthday = DateTime(1988, 10, 12);
        //当前日期
        final date2 = DateTime.now();
        //比较相差的天数
        final difference = date2.difference(birthday).inDays;  //日期相差的函数
        //两次点击间隔超过1秒则重新计时
        _lastPressedAt = DateTime.now();
        print("返回失败"+difference.toString());
        return false;
      }
      print("返回成功");
      return true;
    },child:  Wrap(
      spacing:10,
      runSpacing: 10,
      children: <Widget>[
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/bottomtab");
        },
          child: Text("默认的bottomTab"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/custom_bottomtab");
        },
          child: Text("自定义的BottomTab"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/top_tab");
        },
          child: Text("顶部导航栏"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/flutter_to_android");
        },
          child: Text("Flutter与Android交互"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/route_widget");
        },
          child: Text("路由组件练习"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/text_widget");
        },
          child: Text("Text组件练习"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/edit_widget");
        },
          child: Text("输入框练习"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/layout");
        },
          child: Text("弹性-层叠-定位布局"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/gridview_widget");
        },
          child: Text("Gridview"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/scrollview_widget");
        },
          child: Text("类似于Android Scrollview"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/customscrollview_widget");
        },
          child: Text("CustomScroolView"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/xuanfu_widget");
        },
          child: Text("悬浮停止组件"),
        ),
        RaisedButton(onPressed: (){
          Navigator.pushNamed(context, "/inherited_widget");
        },
          child: Text("InheritedWidget"),
        ),
      ],
    ),);
  }
}
